<%--
  Created by IntelliJ IDEA.
  User: 韩金龙
  Date: 2021/12/13
  Time: 20:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.9.1.min.js"></script>
</head>
<body>
    <form>
        商品名称:<input type="text" name="sname"><br>
        规格:<input type="text" name="ssty"><br>
        品牌:<select id="id" name="pid">
        <option>请选择</option>
        </select><br>
        价格:<input type="text" name="price"><br>
        时间:<input type="date" name="time"><br>
    </form>
    <button onclick="add()">添加</button>
</body>
<script>
    $(function () {
        $.ajax({
            url:"brand.do",
            type:"post",
            dataType:"json",
            success:function(obj) {
                console.log(obj)
                for (let i in obj) {
                    $("#id").append('<option  value="'+obj[i].pid+'">'+obj[i].pname+'</option>')
                }
            }
        })
    })
    function add() {
        $.ajax({
            url:"add.do",
            type:"post",
            data:$("form").serialize(),
            dataType:"json",
            success:function(obj) {
                console.log(obj)
                if (obj>0){
                    alert("添加成功!!")
                    location="list.do"
                }
            }
        })
    }
</script>
</html>
